<template>
  <div class="app-container">
    <el-tabs v-model="activeIndex" type="card">
      <el-tab-pane label="管理员" name="admin">
        <TableAdmin v-if="activeIndex === 'admin'" />
      </el-tab-pane>
      <el-tab-pane label="工程师" name="engineer">
        <template v-if="activeIndex === 'engineer'">
          <eHeader :query="query" type="engineer" :sup-this="supThis" />
          <!--表格渲染-->
          <el-table v-loading="loading" :data="data" size="small" style="width: 100%;" height="500">
            <el-table-column :show-overflow-tooltip="true" prop="serviceproviderName" label="所属服务商" />
            <el-table-column :show-overflow-tooltip="true" prop="personName" label="姓名" />
            <!-- <el-table-column prop="personPassword" label="密码"/>-->
            <!--<el-table-column :show-overflow-tooltip="true" prop="account" label="账号" />-->
            <el-table-column :show-overflow-tooltip="true" prop="phone" label="手机号" />
            <el-table-column :show-overflow-tooltip="true" label="地区">
              <template slot-scope="scope">
                <span>{{ parseArea(scope.row) }}</span>
              </template>
            </el-table-column>
            <el-table-column :show-overflow-tooltip="true" prop="major" label="类型" />
            <el-table-column :show-overflow-tooltip="true" prop="level" label="等级" />
            <el-table-column :show-overflow-tooltip="true" prop="creatTime" label="创建时间">
              <template slot-scope="scope">
                <span>{{ parseTime(scope.row.creatTime) }}</span>
              </template>
            </el-table-column>
            <el-table-column v-if="checkPermission(['ADMIN','TSERVICEPROVIDERPERSON_ALL','TSERVICEPROVIDERPERSON_EDIT','TSERVICEPROVIDERPERSON_DELETE'])" label="操作" width="180px" align="center">
              <template slot-scope="scope">
                <el-popover
                  :ref="scope.row.id"
                  v-permission="['ADMIN','TSERVICEPROVIDERPERSON_ALL','TSERVICEPROVIDERPERSON_DELETE']"
                  placement="top"
                  width="180"
                >
                  <p>确定删除本条数据吗？</p>
                  <div style="text-align: right; margin: 0">
                    <el-button size="mini" type="text" @click="$refs[scope.row.id].doClose()">取消</el-button>
                    <el-button :loading="delLoading" type="primary" size="mini" @click="subDelete(scope.row.id)">确定</el-button>
                  </div>
                  <el-button slot="reference" type="danger" icon="el-icon-delete" size="mini" />
                </el-popover>
              </template>
            </el-table-column>
          </el-table>
          <!--分页组件-->
          <el-pagination
            :total="total"
            style="margin-top: 8px;"
            layout="total, prev, pager, next, sizes"
            @size-change="sizeChange"
            @current-change="pageChange"
          />
        </template>
      </el-tab-pane>
    </el-tabs>
  </div>
</template>

<script>
import checkPermission from '@/utils/permission'
import initData from '@/mixins/initData'
import { del } from '@/api/tServiceproviderPerson'
import { parseTime } from '@/utils/index'
import eHeader from './module/header'
import TableAdmin from './module/tableAdmin'

export default {
  components: { eHeader, TableAdmin },
  mixins: [initData],
  data() {
    return {
      delLoading: false,
      supThis: this,
      activeIndex: 'admin'
    }
  },
  created() {
    this.$nextTick(() => {
      this.init()
    })
  },
  methods: {
    parseTime,
    checkPermission,
    beforeInit() {
      this.url = 'api/tServiceproviderPerson'
      const sort = 'id,desc'
      this.params = { page: this.page, size: this.size, sort: sort }
      const query = this.query
      // const type = query.type
      // const value = query.value
      // if (type && value) { this.params[type] = value }
      if (query.personName) {
        this.params['personName'] = query.personName
      }
      if (query.serviceproviderName) {
        this.params['serviceproviderName'] = query.serviceproviderName
      }
      if (query.phone) {
        this.params['phone'] = query.phone
      }
      if (query.country) {
        this.params['country'] = query.country
      }
      if (query.province) {
        this.params['province'] = query.province
      }
      if (query.city) {
        this.params['city'] = query.city
      }
      if (query.county) {
        this.params['county'] = query.county
      }
      if (query.major) {
        this.params['major'] = query.major
      }
      if (query.level) {
        this.params['level'] = query.level
      }
      return true
    },
    subDelete(id) {
      this.delLoading = true
      del(id).then(res => {
        this.delLoading = false
        this.$refs[id].doClose()
        this.init()
        this.$notify({
          title: '删除成功',
          type: 'success',
          duration: 2500
        })
      }).catch(err => {
        this.delLoading = false
        this.$refs[id].doClose()
        console.log(err)
      })
    },
    parseArea(task) {
      return task.country + '/' + task.province + '/' + task.city + '/' + task.county
    }
  }
}
</script>

<style scoped>

</style>
